#define _CRT_SECURE_NO_WARNINGS 1

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int n, m, c;

bool exec(vector<int>& nums)
{
    sort(nums.begin(), nums.end());
    int len = nums.size();
    for (int i = 1; i < len; i++)
        if (nums[i] - nums[i - 1] + 1 <= m)
            return false;
    return true;
}

int main()
{
    cin >> n >> m >> c;
    map<int, vector<int>>   cor;
    vector<int> fir;
    int a, b;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        while (a--)
        {
            cin >> b;
            cor[b].push_back(i);
        }
    }

    for (auto color : cor)
        for (int i = color.second.size() - 1; i >= 0; i--)
            cor[color.first].push_back(color.second[i] + n);

    int res = 0;
    for (int i = 1; i <= c; i++)
        res += !exec(cor[i]);

    cout << res << endl;
    return 0;
}

